<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>数据字典列表</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<jsp:include page="../util/commScript.jsp">
	   <jsp:param value="<%=basePath %>" name="basePath"/>
	</jsp:include>
  </head>
  <body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
	    <li><a href="javascript:void(0)">首页</a></li>
	    <li><a href="javascript:void(0)">系统管理</a></li>
	    <li><a href="javascript:void(0)">${param.pageTxt==''?'数据字典':param.pageTxt }</a></li>
    </ul>
</div>
    <div id="dictionaryListPage"  class="easyui-layout"  data-options="fit:'true'">
		<input type="hidden" name="parentName" id="parentName" value="${param.pageTxt}" >
		<div class="daohangArea" data-options="region:'west',split:true,title:'导航树'" title="West" style="width:240px;padding:3px">
			
		</div>
		<div data-options="region:'center',title:'${param.pageTxt==''?'数据字典':param.pageTxt }'" title="Center">
		    <div class="dictionaryList"></div>
		</div>
		<div id="dictionaryTools">
	    <!-- 表格工具栏 -->
		<div class="tb_toolbar">
		    <span id="actionBtnArea" style="float:left;margin-right: 5px">
				<a href="javascript:addData('')"  class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增字典</a>
				<a href="javascript:batchAddData()"  class="easyui-linkbutton" data-options="iconCls:'icon-batchAdd'">批量增加</a>
				<a href="javascript:batchDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-no'">批量删除</a>
		    </span>
		    <form action="#" method="post" id="searchForm">
		        <input type="hidden" name="parentUUID" id="dictionaryUUID" value="${param.parentDicUUID }" >
			    <input type="text" class="easyui-textbox" data-options="width:200,prompt:'名称'"  name="dicName" />
				<a href="javascript:seachData()" class="easyui-linkbutton"  data-options="iconCls:'icon-search'">检索</a>
			</form>
		</div>
	    
	    <!-- 表格行工具栏 -->
		<div class="row_toolbar" style="display:none">
			<a href="javascript:addData('#ID#')" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
			<a href="javascript:delData('#ID#')" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true">删除</a><br/>
		</div>
    </div>
    <script type="text/javascript">
          var tableObject = $("#dictionaryListPage .dictionaryList");
          var daohangArea = $('#dictionaryListPage .daohangArea');
          var basePath = getBasePath();
          $(function(){
        	  loadTree();
        	  loadTableList();
          })
          
          function loadTree(){
        	  var parentUUID = $("#dictionaryUUID").val();
        	  var url = getBasePath()+"dictionary/getDictionaryList4Tree.do";
        	  daohangArea.tree({    
          	        url:url,
          	        method:'post',
	          		animate:true,
	          		lines:true,
	          	    //定义查找数据字段
	  		        queryParams: {
	  		        	parentUUID:parentUUID
	  		    	},
	          	    //定义查找数据字段
	          		//单击某个节点触发的事件
	          		onClick: function(node){
	          			if(node.id!="0"){
	          				$("#dictionaryUUID").val(node.id)
	          			}else{
	          				$("#dictionaryUUID").val("0")
	          			}
	          			loadTableList();
	          		}
	          });  
          }
          
          //检索数据
          function seachData(){
             var searChObj = new Object(); 
             var formId = "searchForm";
             $("#"+formId).find("input").each(function(i){
          	   searChObj[$(this).attr("name")] = $(this).val();
             });
             
             $("#"+formId).find("select").each(function(i){
          	   searChObj[$(this).attr("name")] = $(this).val();
             });
             tableObject.datagrid({
          	     queryParams:searChObj
             })
          }
          
          function loadTableList(){
        	var parentUUID = $("#dictionaryUUID").val();
  	    	var placeHeight = $(".place").height();
        	var windowHeight = $(window).height()-(placeHeight+30);
  	    	//向后台加载数据
  	    	tableObject.datagrid({
  	    		height:windowHeight,
  		        url:basePath+'/dictionary/getDictionaryList.do',
  		        //远程请求数据的方式
  		        method:"post",
  		        fit:false,
  		        //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
  		        fitColumns:true,
  		        //调整列的位置
  		        resizeHandle:"right",
  		        //定义设置行的高度,根据该行的内容。设置为false可以提高负载性能
  		        autoRowHeight:"false",
  		        //工具栏
  		        toolbar:"#dictionaryTools .tb_toolbar",
  		        //boolean 是否显示斑马线效果。 
  		        striped:true,
  		        nowrap:false,
  		        idField:"id",
  		        rownumbers:true,//是否显示行号
  		        pagination:true,
  		        loadMsg:"数据加载中，请稍后...",
  		        pageSize:30,//页长
  		        pageList:[15,20,30,40,50],
  		        sortOrder:"id",
  		        singleSelect:false,
  		        checkOnSelect:true,
  		        //定义查找数据字段
  		        queryParams: {
  		        	parentUUID:parentUUID
  		    	},
  		        columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'uuid',title:'编号',width:'10%'},
  		            {field:'dicCode',title:'编码',width:'5%'},
  		            {field:'dicname',title:'名称',width:'12%'},
  		            {field:'aliasName',title:'别名',width:'12%'},
  		            {field:'parentName',title:'父类',width:'12%'},
  		            {field:'sortid',title:'排序',width:'4%'},
  		            {field:'depth',title:'深度',width:'4%'},
  		            {field:'action',title:'操作',width:'170',formatter:function(value, row, index) {
  		            	var reg=new RegExp("#ID#","g"); //创建正则RegExp对象
  		            	return $("#dictionaryTools .row_toolbar").html().replace(reg,row.id);
  					}}
  		        ]]
  		    });
          }
          
        //添加数据
  	    function addData(id){
  	        //验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      	    //得到左边树节点当前选中的项
      	    var daohangArea = $('#dictionaryListPage .daohangArea');
      		var curNode = daohangArea.tree("getSelected");
      		var parentUUID = "";
      		var parentName = "";
      		if(curNode){
      			parentUUID = curNode.id;
      			parentName = curNode.text;
      		}else{
      			parentUUID = $("#dictionaryUUID").val();
      			parentName = $("#parentName").val();
      		}
      	    //计算距离
      		var _width = 650;
      		var _height = 320;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
  	    	$("#editDataFormArea").window({
  	    	    title: '添加字典',
  	    	    width: _width,
  	    	    height: _height,
  	    	    iconCls:'icon-window',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/editDictionary.jsp?id="+id+"&&parentUUID="+parentUUID+"&&parentName="+parentName
  	    	});
  	    }
        
        //批量添加数据
        function batchAddData(){
        	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	        
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      		 //得到左边树节点当前选中的项
      	    var daohangArea = $('#dictionaryListPage .daohangArea');
      		var curNode = daohangArea.tree("getSelected");
      		var parentUUID = "";
      		var parentName = "";
      		if(curNode){
      			parentUUID = curNode.id;
      			parentName = curNode.text;
      		}else{
      			parentUUID = $("#dictionaryUUID").val();
      			parentName = $("#parentName").val();
      		}
      		
      	    //计算距离
      		var _width = 650;
      		var _height = 320;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
  	    	$("#editDataFormArea").window({
  	    	    title: '批量添加字典',
  	    	    width: _width,
  	    	    height: _height,
  	    	    iconCls:'icon-window',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/editAllDictionary.jsp?parentUUID="+parentUUID+"&&parentName="+parentName
  	    	});
        }
          
        //删除单条数据	
  	    function delData(id){
        	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	    	$.messager.confirm('确认对话框', '此操作将永久删除被选中的数据,请确认是否继续操作？', function(flag){
      			if (flag){
      				$.messager.confirm('确认对话框', '如果该字典存在子类，是否一同删除？<br/>1、点【确定】删除子类 <br/> 2、点【取消】只删除本身，不删除子类', function(flag){
	      					var deleteChild = false;
      					    if (flag){
      					    	deleteChild = true;
	      					}
      						$.post(basePath+"/dictionary/delDictionary.do",{id:id,deleteChild:deleteChild},
          		      		    	function(jsonData){
          		      					if(jsonData.code=="00"){
          		      						$.messager.alert('系统提示','删除成功！','success');
          		      					    loadTree();
          		      	        	        loadTableList();
          		      					}else{
          		      						$.messager.alert('系统提示',jsonData.msg,'error');
          		      					}
          		      		},"json");
      					
      				})
      			}
      		});
  	    }
          
        //批量删除
  	    function batchDelete(){
  	    	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
        	
  	    	var ids = [];
  			var rows = tableObject.datagrid('getSelections');
  			if(rows.length<1){
  				$.messager.alert('系统提示','请选中数据后再进行操作！','error');
  				return;
  			}
  			
  			//获取datagrid选中行
  			for (var i = 0; i < rows.length; i++) {
  				ids.push(rows[i].id);
  			}
  			ids = ids.join(',');
  			$.messager.confirm('确认对话框', '此操作将永久删除被选中的数据,请确认是否继续操作？', function(flag){
      			if (flag){
      				$.post(basePath+"/dictionary/delMoreDictionary.do",{ids:ids},
      		    	function(jsonData){
      					if(jsonData.code=="00"){
      						$.messager.alert('系统提示','删除成功！','success');
      						tableObject.datagrid("reload");
  						    daohangArea.tree("reload");
      					}else{
      						$.messager.alert('系统提示','删除失败！','error');
      					}
      		    	},"json");
      			}
      		});			
  		}
        
        //查看详细信息
        function lookDetail(id){
        	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	        
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      		var _width = 650;
      		var _height = 480;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
      		
      		//href:basePath+"manage/xtsz/adminDetail.jsp",
  	    	$("#editDataFormArea").window({
  	    	    title: '查看单位信息',
  	    	    width: _width,
  	    	    height: _height,
  	    	    iconCls:'icon-user',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/adminDetail.jsp?id="+id,
  				onLoad:function(){
  					
  				}
  	    	});
        }
        
        //生成国家地区数据
        function batchGuoJiaData(){
        	$.post(basePath+"dictionary/batchGuoJiaData.do",{},
        		function(jsonData){
        		if(jsonData.code=="00"){
						$.messager.alert('系统提示',jsonData.msg,'success');
					}else{
						$.messager.alert('系统提示',jsonData.msg,'error');
					}   
        	}, "json");
        }
        
        //生成产品导航数据
        function batchNavData(){
        	$.post(basePath+"dictionary/batchNavData.do",{},
        		function(jsonData){
        		if(jsonData.code=="00"){
						$.messager.alert('系统提示',jsonData.msg,'success');
					}else{
						$.messager.alert('系统提示',jsonData.msg,'error');
					}   
        	}, "json");
        }
        
      </script>
	</div>
  </body>
</html>
